home *** CD-ROM | disk | FTP | other *** search
- { control2.pas -- Completed control.pas demonstration. }
-
- program Control;
-
- uses WinTypes, WinProcs, WObjects, Strings;
-
- const
-
- staticOn = 'Select to end program';
- staticOff = 'Click "Ok on" button';
-
- id_CheckBox = 101;
- id_RadioButton = 102;
- id_GroupBox = 103;
- id_Radio1 = 104;
- id_Radio2 = 105;
- id_List = 106;
- id_SingleEd = 107;
- id_MultiEd = 108;
- id_ComboBox = 109;
- id_ScrollBar = 110;
-
-
- type
-
- PMultiEd = ^TMultiEd;
- TMultiEd = object(TEdit)
- constructor Init(AParent: PWindowsObject; AnId: Integer;
- ATitle: PChar; X, Y, W, H: Integer; ATextLen: Word);
- procedure DefWndProc(var Msg: TMessage); virtual;
- end;
-
- ControlApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PControlWindow = ^ControlWindow;
- ControlWindow = object(TWindow)
- OkButton: PButton;
- GroupBox: PGroupBox;
- DefRadio: PRadioButton;
- Static: PStatic;
- ListBox: PListBox;
- SingleEd: PEdit;
- MultiEd: PMultiEd;
- ComboBox: PComboBox;
- ScrollBar: PScrollBar;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure SetupWindow; virtual;
- procedure IDOk(var Msg: TMessage);
- virtual id_First + id_Ok;
- procedure IDCheckBox(var Msg: TMessage);
- virtual id_First + id_CheckBox;
- procedure IDRadio1(var Msg: TMessage);
- virtual id_First + id_Radio1;
- procedure IDRadio2(var Msg: TMessage);
- virtual id_First + id_Radio2;
- procedure IDList(var Msg: TMessage);
- virtual id_First + id_List;
- end;
-
-
- { TMultiEd }
-
- {- Construct TMultiEd instances }
- constructor TMultiEd.Init(AParent: PWindowsObject; AnId: Integer;
- ATitle: PChar; X, Y, W, H: Integer; ATextLen: Word);
- begin
- TEdit.Init(AParent, AnId, ATitle, X, Y, W, H, ATextLen, true);
- Attr.Style := Attr.Style and not (es_AutoHScroll or ws_HScroll)
- end;
-
- {- Modify DefWndProc to handle Tab and Shift-Tab }
- procedure TMultiEd.DefWndProc(var Msg: TMessage);
- begin
- if (Msg.Message = wm_KeyDown) and (Msg.WParam = vk_Tab) then
- begin
- if GetKeyState(vk_Shift) < 0 then
- SetFocus(Previous^.HWindow)
- else
- SetFocus(Next^.HWindow);
- Exit
- end;
- TEdit.DefWndProc(Msg)
- end;
-
- { ControlApplication }
-
- {- Initialize ControlApplication object's window }
- procedure ControlApplication.InitMainWindow;
- begin
- MainWindow := New(PControlWindow, Init(nil, 'Control Demo'))
- end;
-
-
- { ControlWindow }
-
- {- Construct ControlWindow object }
- constructor ControlWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- var
- AControl: PControl;
- begin
- TWindow.Init(AParent, ATitle);
- EnableKBHandler;
- with Attr do
- begin
- X := 0; Y := 0; W := 500; H := 350
- end;
-
- OkButton := New(PButton, Init(@Self, id_Ok, 'Ok',
- 390, 280, 80, 30, true));
-
- AControl := New(PCheckBox, Init(@Self, id_CheckBox,
- 'Check This Out', 50, 275, 120, 40, nil));
-
- GroupBox := New(PGroupBox, Init(@Self, id_GroupBox,
- 'Group', 10, 10, 100, 100));
-
- DefRadio := New(PRadioButton, Init(@Self, id_Radio1,
- 'Ok on', 20, 30, 60, 40, GroupBox));
-
- AControl := New(PRadioButton, Init(@Self, id_Radio2,
- 'Ok off', 20, 65, 60, 40, GroupBox));
-
- AControl := New(PStatic, Init(@Self, -1,
- 'Out of Control', 380, 10, 150, 25, 14));
-
- Static := New(PStatic, Init(@Self, -1,
- staticOn, 325, 250, 200, 25, StrLen(staticOn)));
-
- ListBox := New(PListBox, Init(@Self, id_List,
- 150, 20, 150, 160));
-
- SingleEd := New(PEdit, Init(@Self, id_SingleEd,
- 'Single-line edit', 150, 195, 150, 25, 128, false));
-
- MultiEd := New(PMultiEd, Init(@Self, id_MultiEd,
- 'Multi-line edit', 10, 120, 125, 100, 2048));
-
- ComboBox := New(PComboBox, Init(@Self, id_ComboBox,
- 320, 40, 150, 185, 0, 128));
-
- ScrollBar := New(PScrollBar, Init(@Self, id_ScrollBar,
- 10, 250, 300, 20, true));
-
- end;
-
- procedure ControlWindow.SetupWindow;
- begin
- TWindow.SetupWindow;
- SetFocus(OkButton^.HWindow);
- DefRadio^.Check;
- ListBox^.AddString('Control Demo');
- ListBox^.AddString('Pascal');
- ListBox^.AddString('C++');
- ListBox^.AddString('BASIC');
- ListBox^.AddString('Batch');
- ComboBox^.AddString('Windows');
- ComboBox^.AddString('DOS');
- ComboBox^.AddString('OS/2');
- ComboBox^.AddString('Unix');
- end;
-
- {- Respond to selection of Ok button }
- procedure ControlWindow.IDOk(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- {- Respond to checkbox events }
- procedure ControlWindow.IDCheckBox(var Msg: TMessage);
- begin
- MessageBeep(0)
- end;
-
- {- Respond to changes in radio button 1 }
- procedure ControlWindow.IDRadio1(var Msg: TMessage);
- begin
- OkButton^.Show(sw_Show);
- Static^.SetText(staticOn);
- end;
-
- {- Respond to selecting radio button 2 }
- procedure ControlWindow.IDRadio2(var Msg: TMessage);
- begin
- OkButton^.Show(sw_Hide);
- Static^.SetText(staticOff);
- end;
-
- {- Respond to list box notification events }
- procedure ControlWindow.IDList(var Msg: TMessage);
- var
- Len: Integer;
- Buffer: array[0 .. 24] of Char;
- begin
- if Msg.LParamHi = lbn_SelChange then
- begin
- Len := ListBox^.GetSelString(Buffer, Sizeof(Buffer) - 1);
- if Len > 0 then
- SetWindowText(HWindow, Buffer)
- end
- end;
-
- var
-
- ControlApp: ControlApplication;
-
- begin
- ControlApp.Init('ControlApp');
- ControlApp.Run;
- ControlApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/9/1991
- ---------------------------------------------------------------}
-
-